<template>
  <div>
    <form action="/">
      <van-search
        v-model="value"
        show-action
        placeholder="请输入搜索关键词"
        @input="onSearch"
        @cancel="onCancel"
      />
    </form>
    <van-list
  v-model="loading"
  :finished="finished"
  @load="onSearch"
>
  <van-cell v-for="(item, index) in list" :key="index" :title="item.communityName" @click="$router.push({name:'addhouse',params:{
      label: item.communityName,
      value: item.community
    }})"/>
</van-list>
  </div>
</template>

<script>
import { getCity } from '@/utils/storage'
import { getCommunity } from '@/api/homo'
export default {
  data () {
    return {
      value: '',
      list: [],
      loading: false,
      finished: false
    }
  },
  methods: {
    async onSearch () {
      if (this.value) {
        this.loading = true
        const { value } = await getCity()
        const { body } = await getCommunity({
          id: value,
          name: this.value
        })
        this.list = body
        setTimeout(() => {
          console.log(body)
          this.finished = true
        }, 0)
      } else {
        this.loading = true
        this.finished = true
      }
    },
    onCancel () {
      this.$router.back()
    }
  }
}
</script>

<style>

</style>
